package pack1;

public class java10 {
    public static void main(String[] args){
        String str1 = "TAGGGATTAACCGTTATATATATATAGCCATGGATGGATCGATTATATAACCGTTATATATATATAGCCATGGATCGATTATA";
        int length = str1.length();
        int arry[]=new int[(length/16)+1];
        char crry[]=new char[length];
        int k=0;
        int b=0;
        int brry[]=new int[2];
        System.out.print("压缩后为：");
        brry=compress(arry,length,str1);
        k=brry[0];
        b=brry[1];
        System.out.print("解压缩后为：");
        crry=compress(arry,length,k,b);
        for (int i = 0; i <length; i++) {
            System.out.print(crry[i]);
        }
        System.out.print("\n");
        System.out.println("压缩比为："+(b+1)+":"+length);
    }
    public static int[] compress(int arry[],int length,String str1){
        int b=0;
        int k=0;
        for (int i = 0; i <length; i++,k++) {
            char ch=str1.charAt(i);
            int a=4;
            if(k==16){
                b=b+1;
                k=0;
            }
            if(ch=='A'){
                System.out.print("00");
                a=0;}
            if(ch=='C'){
                System.out.print("01");
                a=1;}
            if(ch=='G'){
                System.out.print("10");
                a=2;}
            if(ch=='T'){
                System.out.print("11");
                a=3;}
            if(a==4)
                System.out.println("wrong");
            arry[b]=arry[b]*4;
            arry[b]+=a;
        }
        System.out.print("\n");
        int brry[]=new int[2];
        brry[0]=k;
        brry[1]=b;
        return brry;
    }
    public static char[] compress(int arry[],int length,int k,int b){
        char crry[]=new char[length];
        for (int i = length-1; i>-1; i--,k--) {
            if(k==0){
              k=16;
              b--;
            }
            int zhi = arry[b] & 0b11;
            arry[b]=arry[b]>>2;
        if(zhi==0)
            crry[i]='A';
        if(zhi==1)
            crry[i]='C';
        if(zhi==2)
            crry[i]='G';
        if(zhi==3)
            crry[i]='T';
        }
        return crry;
    }
}
